Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@babel/plugin-transform-async-to-generator
Advanced tools
Turn async functions into ES2015 generators
The @babel/plugin-transform-async-to-generator package is a Babel plugin that transforms async functions into generator functions using the regenerator runtime, which is a part of the Facebook Regenerator project. This transformation allows async functions to be used in environments that do not natively support async/await syntax by converting them into ES2015/ES6 compatible code.
Transform async functions to generators
This feature allows developers to write asynchronous code using the modern async/await syntax and have it transformed into generator functions that are compatible with older JavaScript engines.
async function foo() {
await bar();
}
// Transforms to:
function foo() {
return regeneratorRuntime.async(function foo$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return regeneratorRuntime.awrap(bar());
case 2:
case "end":
return _context.stop();
}
}
}, null, this);
}
This package is similar to @babel/plugin-transform-async-to-generator in that it transforms async functions, but it does so by delegating to a specified module method, allowing for custom handling of async functions.
Fast-async is a Babel plugin that uses nodent to transform async/await functions. It is designed to be faster than the regenerator-based approach used by @babel/plugin-transform-async-to-generator and does not require a runtime.
While not a direct alternative, babel-preset-env includes the capability to transform async functions when the target environments specified do not support them natively. It uses @babel/plugin-transform-async-to-generator as part of its transformation suite when necessary.
Turn async functions into ES2015 generators
See our website @babel/plugin-transform-async-to-generator for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-async-to-generator
or using yarn:
yarn add @babel/plugin-transform-async-to-generator --dev
v7.25.9 (2024-10-22)
babel-parser
, babel-template
, babel-types
syntacticPlaceholders
mode (@liuxingbaoyu)babel-helper-compilation-targets
, babel-preset-env
ClassAccessorProperty
to prevent the no-undef
rule (@victorenator)babel-parser
, babel-types
VISITOR_KEYS
etc. faster to access (@liuxingbaoyu)FAQs
Turn async functions into ES2015 generators
The npm package @babel/plugin-transform-async-to-generator receives a total of 18,759,418 weekly downloads. As such, @babel/plugin-transform-async-to-generator popularity was classified as popular.
We found that @babel/plugin-transform-async-to-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.